/* test_arc4.c
**
** Copyright (c) 2007, Meadhbh S. Hamrick
** All rights reserved.
** 
** Redistribution  and  use  in  source  and  binary  forms,  with  or  without
** modification, are permitted provided that the following conditions are met:
** 
**  * Redistributions of  source code must  retain the above  copyright notice,
**    this list of conditions and the following disclaimer.
** 
**  * Redistributions in binary form must reproduce the above copyright notice,
**    this list of conditions and the following disclaimer in the documentation
**    and/or other materials provided with the distribution.
** 
**  * Neither the  name of  Project Meadhbh  nor the names of  its contributors
**    may be used  to endorse  or promote  products derived from this  software
**    without specific prior written permission.
** 
** THIS SOFTWARE IS PROVIDED BY  THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY  EXPRESS OR IMPLIED WARRANTIES,  INCLUDING, BUT NOT  LIMITED TO, THE
** IMPLIED WARRANTIES  OF MERCHANTABILITY AND FITNESS FOR  A PARTICULAR PURPOSE
** ARE DISCLAIMED.  IN NO  EVENT SHALL THE  COPYRIGHT OWNER OR  CONTRIBUTORS BE
** LIABLE  FOR  ANY  DIRECT,   INDIRECT,  INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR
** CONSEQUENTIAL  DAMAGES  (INCLUDING,  BUT  NOT  LIMITED  TO,  PROCUREMENT  OF
** SUBSTITUTE GOODS  OR SERVICES;  LOSS OF USE,  DATA, OR PROFITS;  OR BUSINESS
** INTERRUPTION)  HOWEVER CAUSED  AND ON  ANY THEORY  OF LIABILITY,  WHETHER IN
** CONTRACT,  STRICT LIABILITY,  OR  TORT (INCLUDING  NEGLIGENCE OR  OTHERWISE)
** ARISING IN ANY WAY  OUT OF THE USE OF THIS SOFTWARE,  EVEN IF ADVISED OF THE
** POSSIBILITY OF SUCH DAMAGE.
** 
** $Id: test_arc4.c 66 2007-11-08 07:18:51Z msh.mobile $
*/

/** \file test_arc4.c
**  \brief Test ARC4 Stream Cipher
**
** This file  implements the tests that are  referenced in test_crypto.c.
** It is  assumed that the initalization  function suite_arc4_init() will
** be  called before any  of the  test_*() functions.  The initialization
** function does  all the "heavy  lifting" of creating  contexts, setting
** the key, encrypting and so forth.  The individual tests simply compare
** output and intermediate values with known good test values.
** 
** "Canonical" test  vectors for ARC4 are  hard to come by.  In 1999, RSA
** published an internet  draft with a single test  vector. In 1994, test
** vectors were published on sci.crypt. Even the Wikipedia has a few test
** vectors.
** 
** Numerous  tests for cloning  behavior are  performed. Cloning  is used
** extensively in  these tests.  If it doesn't  work, then  it's unlikely
** that anything  will work. But we perform  a number of tests  to see if
** there are particular problems with cloning before or after various arc4
** function calls.
** 
** We test the mc_ssc_arc4_clear() function by testing to see if the 
** content of the context is set to zero.
*/

/* Macro Definitions */
#define MC_SSC_ARC4_TEST_MAX_CONTEXTS 6
#define MC_SSC_ARC4_TEST_MAX_VECTORS 1

/* File Includes */
#include <string.h>
#include "mutil.h"
#include "mcrypto/arc4.h"
#include "test_arc4.h"
#include <CUnit/CUnit.h>
#include <stdlib.h>
#include <stdio.h>

/* Typedefs, Structs, Unions, Enums, etc. */

/* Static Function Prototypes */

/* Variable Declarations */
tMCArc4 arc4_actual_contexts [ MC_SSC_ARC4_TEST_MAX_CONTEXTS ];
tMCArc4 arc4_expected_contexts [ MC_SSC_ARC4_TEST_MAX_CONTEXTS ] = {
  {
    .a = 0x00000000,
    .b = 0x00000000,
    .sbox = {
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
    }
  },
  {
    .a = 0x00000000,
    .b = 0x00000000,
    .sbox = {
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
    }
  },
  {
    .a = 0x00000000,
    .b = 0x00000000,
    .sbox = {
      0x58, 0x69, 0x97, 0x0A, 0x06, 0x34, 0x3D, 0x7E, 0x76, 0x3F, 0x32, 0xA6, 0x6A, 0x56, 0x2C, 0x6B,
      0x90, 0xE3, 0x45, 0x6F, 0xE4, 0xDE, 0x5B, 0x2A, 0xD2, 0x77, 0x9D, 0x4E, 0x24, 0x51, 0x7F, 0xB4,
      0x38, 0x57, 0x19, 0x82, 0xD5, 0x16, 0x09, 0x48, 0x93, 0x64, 0xBC, 0x5E, 0x53, 0xA4, 0x3B, 0x7A,
      0xFA, 0xB5, 0x72, 0x29, 0x2B, 0xC4, 0xCE, 0x4D, 0x4B, 0x60, 0x00, 0xF8, 0x4A, 0x67, 0xFC, 0x70,
      0xCB, 0x80, 0x5D, 0xBF, 0x79, 0x1A, 0x8A, 0x98, 0x15, 0x03, 0x23, 0xEE, 0x86, 0xE0, 0xC5, 0xB3,
      0x39, 0x66, 0x42, 0xAB, 0x73, 0x85, 0x89, 0x3E, 0xCA, 0x2F, 0xCC, 0x43, 0x02, 0x14, 0x18, 0x65,
      0x78, 0x31, 0xEC, 0x13, 0x0B, 0x52, 0x10, 0xAC, 0xA3, 0x88, 0x28, 0xE8, 0x7B, 0xF7, 0x0F, 0x62,
      0x44, 0xBB, 0x4C, 0xA7, 0xEB, 0x8B, 0x92, 0xC7, 0xAA, 0x9E, 0xFF, 0xE2, 0x81, 0x3A, 0xB0, 0xA1,
      0x9C, 0x55, 0xD6, 0x6D, 0x21, 0x94, 0xDF, 0x11, 0x41, 0xF0, 0x0D, 0xE5, 0x91, 0xB9, 0x8D, 0x54,
      0x1B, 0xCD, 0x2D, 0x2E, 0xF2, 0xB6, 0xD3, 0xB1, 0xE1, 0x17, 0xE7, 0xC8, 0x63, 0xA9, 0x8E, 0xD0,
      0xBD, 0x30, 0x7D, 0x59, 0xFD, 0xED, 0x99, 0xDC, 0xB7, 0x9B, 0x9A, 0xBE, 0x5C, 0x61, 0xAE, 0x1F,
      0x8F, 0x71, 0x6C, 0xAD, 0x0C, 0x35, 0xD7, 0xC3, 0xCF, 0xA5, 0xF6, 0xA0, 0x1C, 0x26, 0x7C, 0x95,
      0xD8, 0x8C, 0xAF, 0x20, 0x1D, 0x25, 0xE9, 0x33, 0x12, 0xD9, 0x84, 0xFB, 0x04, 0x01, 0x0E, 0x5F,
      0xEF, 0x68, 0xDA, 0x9F, 0xB8, 0xF5, 0x50, 0x75, 0xD4, 0xF4, 0xDD, 0x4F, 0x49, 0x05, 0x37, 0x47,
      0x22, 0x08, 0xF1, 0xBA, 0x46, 0xEA, 0xA2, 0x87, 0x83, 0x36, 0x3C, 0xFE, 0xD1, 0xC1, 0x40, 0xC2,
      0x6E, 0xDB, 0xF3, 0xF9, 0x1E, 0x27, 0xC6, 0xB2, 0x96, 0xC9, 0xA8, 0xC0, 0x74, 0x5A, 0x07, 0xE6
    }
  },
  {
    .a = 0x00000010,
    .b = 0x000000C1,
    .sbox = {
      0x97, 0x88, 0x58, 0x32, 0x90, 0x79, 0x55, 0xE6, 0x8B, 0x0C, 0x7C, 0x0B, 0x0E, 0xD5, 0x39, 0xA0,
      0x8C, 0xE3, 0x45, 0x6F, 0xE4, 0xDE, 0x5B, 0x2A, 0xD2, 0x77, 0x9D, 0x4E, 0x24, 0x51, 0x7F, 0xB4,
      0x38, 0x57, 0x19, 0x82, 0x56, 0x16, 0x09, 0x48, 0x93, 0x64, 0xBC, 0x5E, 0x53, 0xA4, 0x3B, 0x7A,
      0xFA, 0xB5, 0x72, 0x29, 0x2B, 0xC4, 0xCE, 0x4D, 0x4B, 0x60, 0x00, 0xF8, 0x4A, 0x67, 0xFC, 0x70,
      0xCB, 0x80, 0x5D, 0xBF, 0x34, 0x1A, 0x8A, 0x98, 0x15, 0x03, 0x23, 0xEE, 0x86, 0xE0, 0xC5, 0xB3,
      0x2C, 0x66, 0x42, 0xAB, 0x73, 0x85, 0x89, 0x3E, 0xCA, 0x2F, 0xCC, 0x43, 0x02, 0x14, 0x18, 0x65,
      0x78, 0x31, 0xEC, 0x13, 0xA6, 0x52, 0x10, 0xAC, 0xA3, 0x69, 0x28, 0xE8, 0x7B, 0xF7, 0x0F, 0x62,
      0x44, 0xBB, 0x4C, 0xA7, 0xEB, 0x76, 0x92, 0xC7, 0xAA, 0x9E, 0xFF, 0xE2, 0x81, 0x3A, 0xB0, 0xA1,
      0x9C, 0x3D, 0xD6, 0x6D, 0x21, 0x94, 0xDF, 0x11, 0x41, 0xF0, 0x0D, 0xE5, 0x91, 0xB9, 0x8D, 0x54,
      0x1B, 0xCD, 0x2D, 0x2E, 0xF2, 0xB6, 0xD3, 0xB1, 0xE1, 0x17, 0xE7, 0xC8, 0x63, 0xA9, 0x8E, 0xD0,
      0xBD, 0x30, 0x7D, 0x59, 0xFD, 0xED, 0x99, 0xDC, 0xB7, 0x9B, 0x9A, 0xBE, 0x5C, 0x61, 0xAE, 0x1F,
      0x8F, 0x71, 0x6C, 0xAD, 0x3F, 0x35, 0xD7, 0xC3, 0xCF, 0xA5, 0xF6, 0x6B, 0x1C, 0x26, 0x0A, 0x95,
      0xD8, 0x06, 0xAF, 0x20, 0x1D, 0x25, 0xE9, 0x33, 0x12, 0xD9, 0x84, 0xFB, 0x04, 0x01, 0x6A, 0x5F,
      0xEF, 0x68, 0xDA, 0x9F, 0xB8, 0xF5, 0x50, 0x75, 0xD4, 0xF4, 0xDD, 0x4F, 0x49, 0x05, 0x37, 0x47,
      0x22, 0x08, 0xF1, 0xBA, 0x46, 0xEA, 0xA2, 0x87, 0x83, 0x36, 0x3C, 0xFE, 0xD1, 0xC1, 0x40, 0xC2,
      0x6E, 0xDB, 0xF3, 0xF9, 0x1E, 0x27, 0xC6, 0xB2, 0x96, 0xC9, 0xA8, 0xC0, 0x74, 0x5A, 0x07, 0x7E
    }
  },
  {
    .a = 0x00000010,
    .b = 0x000000C1,
    .sbox = {
      0x97, 0x88, 0x58, 0x32, 0x90, 0x79, 0x55, 0xE6, 0x8B, 0x0C, 0x7C, 0x0B, 0x0E, 0xD5, 0x39, 0xA0,
      0x8C, 0xE3, 0x45, 0x6F, 0xE4, 0xDE, 0x5B, 0x2A, 0xD2, 0x77, 0x9D, 0x4E, 0x24, 0x51, 0x7F, 0xB4,
      0x38, 0x57, 0x19, 0x82, 0x56, 0x16, 0x09, 0x48, 0x93, 0x64, 0xBC, 0x5E, 0x53, 0xA4, 0x3B, 0x7A,
      0xFA, 0xB5, 0x72, 0x29, 0x2B, 0xC4, 0xCE, 0x4D, 0x4B, 0x60, 0x00, 0xF8, 0x4A, 0x67, 0xFC, 0x70,
      0xCB, 0x80, 0x5D, 0xBF, 0x34, 0x1A, 0x8A, 0x98, 0x15, 0x03, 0x23, 0xEE, 0x86, 0xE0, 0xC5, 0xB3,
      0x2C, 0x66, 0x42, 0xAB, 0x73, 0x85, 0x89, 0x3E, 0xCA, 0x2F, 0xCC, 0x43, 0x02, 0x14, 0x18, 0x65,
      0x78, 0x31, 0xEC, 0x13, 0xA6, 0x52, 0x10, 0xAC, 0xA3, 0x69, 0x28, 0xE8, 0x7B, 0xF7, 0x0F, 0x62,
      0x44, 0xBB, 0x4C, 0xA7, 0xEB, 0x76, 0x92, 0xC7, 0xAA, 0x9E, 0xFF, 0xE2, 0x81, 0x3A, 0xB0, 0xA1,
      0x9C, 0x3D, 0xD6, 0x6D, 0x21, 0x94, 0xDF, 0x11, 0x41, 0xF0, 0x0D, 0xE5, 0x91, 0xB9, 0x8D, 0x54,
      0x1B, 0xCD, 0x2D, 0x2E, 0xF2, 0xB6, 0xD3, 0xB1, 0xE1, 0x17, 0xE7, 0xC8, 0x63, 0xA9, 0x8E, 0xD0,
      0xBD, 0x30, 0x7D, 0x59, 0xFD, 0xED, 0x99, 0xDC, 0xB7, 0x9B, 0x9A, 0xBE, 0x5C, 0x61, 0xAE, 0x1F,
      0x8F, 0x71, 0x6C, 0xAD, 0x3F, 0x35, 0xD7, 0xC3, 0xCF, 0xA5, 0xF6, 0x6B, 0x1C, 0x26, 0x0A, 0x95,
      0xD8, 0x06, 0xAF, 0x20, 0x1D, 0x25, 0xE9, 0x33, 0x12, 0xD9, 0x84, 0xFB, 0x04, 0x01, 0x6A, 0x5F,
      0xEF, 0x68, 0xDA, 0x9F, 0xB8, 0xF5, 0x50, 0x75, 0xD4, 0xF4, 0xDD, 0x4F, 0x49, 0x05, 0x37, 0x47,
      0x22, 0x08, 0xF1, 0xBA, 0x46, 0xEA, 0xA2, 0x87, 0x83, 0x36, 0x3C, 0xFE, 0xD1, 0xC1, 0x40, 0xC2,
      0x6E, 0xDB, 0xF3, 0xF9, 0x1E, 0x27, 0xC6, 0xB2, 0x96, 0xC9, 0xA8, 0xC0, 0x74, 0x5A, 0x07, 0x7E
    }
  },
  {
    .a = 0x00000010,
    .b = 0x000000C1,
    .sbox = {
      0x97, 0x88, 0x58, 0x32, 0x90, 0x79, 0x55, 0xE6, 0x8B, 0x0C, 0x7C, 0x0B, 0x0E, 0xD5, 0x39, 0xA0,
      0x8C, 0xE3, 0x45, 0x6F, 0xE4, 0xDE, 0x5B, 0x2A, 0xD2, 0x77, 0x9D, 0x4E, 0x24, 0x51, 0x7F, 0xB4,
      0x38, 0x57, 0x19, 0x82, 0x56, 0x16, 0x09, 0x48, 0x93, 0x64, 0xBC, 0x5E, 0x53, 0xA4, 0x3B, 0x7A,
      0xFA, 0xB5, 0x72, 0x29, 0x2B, 0xC4, 0xCE, 0x4D, 0x4B, 0x60, 0x00, 0xF8, 0x4A, 0x67, 0xFC, 0x70,
      0xCB, 0x80, 0x5D, 0xBF, 0x34, 0x1A, 0x8A, 0x98, 0x15, 0x03, 0x23, 0xEE, 0x86, 0xE0, 0xC5, 0xB3,
      0x2C, 0x66, 0x42, 0xAB, 0x73, 0x85, 0x89, 0x3E, 0xCA, 0x2F, 0xCC, 0x43, 0x02, 0x14, 0x18, 0x65,
      0x78, 0x31, 0xEC, 0x13, 0xA6, 0x52, 0x10, 0xAC, 0xA3, 0x69, 0x28, 0xE8, 0x7B, 0xF7, 0x0F, 0x62,
      0x44, 0xBB, 0x4C, 0xA7, 0xEB, 0x76, 0x92, 0xC7, 0xAA, 0x9E, 0xFF, 0xE2, 0x81, 0x3A, 0xB0, 0xA1,
      0x9C, 0x3D, 0xD6, 0x6D, 0x21, 0x94, 0xDF, 0x11, 0x41, 0xF0, 0x0D, 0xE5, 0x91, 0xB9, 0x8D, 0x54,
      0x1B, 0xCD, 0x2D, 0x2E, 0xF2, 0xB6, 0xD3, 0xB1, 0xE1, 0x17, 0xE7, 0xC8, 0x63, 0xA9, 0x8E, 0xD0,
      0xBD, 0x30, 0x7D, 0x59, 0xFD, 0xED, 0x99, 0xDC, 0xB7, 0x9B, 0x9A, 0xBE, 0x5C, 0x61, 0xAE, 0x1F,
      0x8F, 0x71, 0x6C, 0xAD, 0x3F, 0x35, 0xD7, 0xC3, 0xCF, 0xA5, 0xF6, 0x6B, 0x1C, 0x26, 0x0A, 0x95,
      0xD8, 0x06, 0xAF, 0x20, 0x1D, 0x25, 0xE9, 0x33, 0x12, 0xD9, 0x84, 0xFB, 0x04, 0x01, 0x6A, 0x5F,
      0xEF, 0x68, 0xDA, 0x9F, 0xB8, 0xF5, 0x50, 0x75, 0xD4, 0xF4, 0xDD, 0x4F, 0x49, 0x05, 0x37, 0x47,
      0x22, 0x08, 0xF1, 0xBA, 0x46, 0xEA, 0xA2, 0x87, 0x83, 0x36, 0x3C, 0xFE, 0xD1, 0xC1, 0x40, 0xC2,
      0x6E, 0xDB, 0xF3, 0xF9, 0x1E, 0x27, 0xC6, 0xB2, 0x96, 0xC9, 0xA8, 0xC0, 0x74, 0x5A, 0x07, 0x7E
    }
  },
};
uint8_t arc4_actual_key_0[ 8 ] = { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 };
uint8_t arc4_actual_input_0[ 16 ] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 };
uint8_t arc4_actual_output_0 [ 16 ];
uint8_t arc4_expected_output_0 [ 16 ] = { 0xda, 0xe1, 0x0f, 0xb4, 0xe8, 0x86, 0xc6, 0x67, 0x10, 0x03, 0xcb, 0x32, 0x28, 0x06, 0x39, 0x3d };
uint8_t arc4_recovered_output_0 [ 16 ];
uint32_t arc4_bytes_encrypted[ MC_SSC_ARC4_TEST_MAX_VECTORS ];
uint32_t arc4_bytes_decrypted[ MC_SSC_ARC4_TEST_MAX_VECTORS ];

/* Function Definitions */

/** \fn int suite_arc4_init( void )
**  \brief Calls various arc4 functions in preparation for value checking.
**  \returns 0 (success)
** 
** This is  the function where "rubber  meets the road." We  call all the
** functions  under test  in this  initialization function  and  in later
** tests simply compare the values we get with known good values.
** 
** The algorithm-specific  functions don't  return error codes  and don't
** check parameters. Ergo, we won't  know if there's a failure during the
** init routine's run. We get that info later in the test_*()
** functions.
*/

int suite_arc4_init() {
  /* Clear Context 0 (to verify we can create a context) */
  mc_ssc_arc4_clear( & ( arc4_actual_contexts[ 0 ] ) );

  /* Clone Context 0 into Context 1 (to verify we can clone an uninitialized context) */
  mc_ssc_arc4_clone( & ( arc4_actual_contexts[ 1 ] ), & ( arc4_actual_contexts[ 0 ] ) );

  /* Clone Context 1 into Context 2 (because we need something to work with) */
  mc_ssc_arc4_clone( & ( arc4_actual_contexts[ 2 ] ), & ( arc4_actual_contexts[ 1 ] ) );

  /* Initialize Context 2 with key 0 (to test initialization) */
  mc_ssc_arc4_initialize( & ( arc4_actual_contexts[ 2 ] ), arc4_actual_key_0, 8 );

  /* Clone Context 2 into Context 3 (beacuse we need to save context 2's state to test later, and to verify that we can clone initialized contexts ) */
  mc_ssc_arc4_clone( & ( arc4_actual_contexts[ 3 ] ), & ( arc4_actual_contexts[ 2 ] ) );

  /* encrypt plaintext 0 with context 3 */
  mc_ssc_arc4_encrypt( & ( arc4_actual_contexts[ 3 ] ), arc4_actual_input_0, 16, arc4_actual_output_0, 16, & ( arc4_bytes_encrypted[ 0 ] ) );

  /* Clone Context 3 into Context 4 (to verify we can clone used contexts) */
  mc_ssc_arc4_clone( & ( arc4_actual_contexts[ 4 ] ), & ( arc4_actual_contexts[ 3 ] ) );
  
  /* Clone Context 2 into Context 5 (because we want to decrypt ciphertext 0) */  mc_ssc_arc4_clone( & ( arc4_actual_contexts[ 5 ] ), & ( arc4_actual_contexts[ 2 ] ) );

  /* Decrypt ciphertext 0 with context 5 */
  mc_ssc_arc4_decrypt( & ( arc4_actual_contexts[ 5 ] ), arc4_actual_output_0, 16, arc4_recovered_output_0, 16, &( arc4_bytes_decrypted[ 0 ] ) );

  return( 0 );
}

/** \fn void test_arc4_vectors( void )
**  \brief Tests that we produced the right output
** 
*/

void test_arc4_vectors( ) {
  CU_ASSERT_EQUAL( 0, memcmp( arc4_actual_output_0, arc4_expected_output_0, 16 ) );
  CU_ASSERT_EQUAL( 0, memcmp( arc4_recovered_output_0, arc4_actual_input_0, 16 ) );
  CU_ASSERT_EQUAL( 16, arc4_bytes_decrypted[ 0 ] );
  CU_ASSERT_EQUAL( 16, arc4_bytes_encrypted[ 0 ] );
}

/** \fn void test_mc_ssc_arc4_clone( void )
**  \brief Tests our ability to clone hash contexts
** 
** In this  test, we  look to  see if our  ability to  copy a  context is
** dependent on  the state of the  context. I would be  very surprised if
** this fails.
*/

void test_mc_ssc_arc4_clone( ) {
  CU_ASSERT_EQUAL( 0, memcmp( & ( arc4_actual_contexts[0] ), & ( arc4_expected_contexts[0] ), sizeof( tMCArc4 ) ) );
  CU_ASSERT_EQUAL( 0, memcmp( & ( arc4_actual_contexts[1] ), & ( arc4_expected_contexts[1] ), sizeof( tMCArc4 ) ) );
  CU_ASSERT_EQUAL( 0, memcmp( & ( arc4_actual_contexts[2] ), & ( arc4_expected_contexts[2] ), sizeof( tMCArc4 ) ) );
  CU_ASSERT_EQUAL( 0, memcmp( & ( arc4_actual_contexts[3] ), & ( arc4_expected_contexts[3] ), sizeof( tMCArc4 ) ) );
  CU_ASSERT_EQUAL( 0, memcmp( & ( arc4_actual_contexts[4] ), & ( arc4_expected_contexts[4] ), sizeof( tMCArc4 ) ) );
  CU_ASSERT_EQUAL( 0, memcmp( & ( arc4_actual_contexts[5] ), & ( arc4_expected_contexts[5] ), sizeof( tMCArc4 ) ) );
}

/** \fn void test_mc_ssc_arc4_clear( void )
**  \brief Tests to ensure that sensitive data is cleared
** 
*/

void test_mc_ssc_arc4_clear( ) {
  uint8_t *test_data[ sizeof( tMCArc4 ) ];

  memset( test_data, 0, sizeof( tMCArc4 ) );

  CU_ASSERT_EQUAL( 0, memcmp( & ( arc4_actual_contexts[0] ), test_data, sizeof( tMCArc4 ) ) );
}

/** \fn void test_mc_ssc_arc4_initialize( void )
**  \brief Tests the ability to initiailze a newly allocated hashing context. 
** 
*/

void test_mc_ssc_arc4_initialize( ) {
  /* Actually we test this already in the clone tests */
}

/** \fn void test_mc_ssc_arc4_update( void )
**  \brief Tests the hash update function
** 
*/

void test_mc_ssc_arc4_update( ) {
  /* ditto */
}

/** \fn void test_mc_ssc_arc4_keystream( void )
**  \brief Tests the hash update function
** 
*/

void test_mc_ssc_arc4_keystream( ) {
  /* todo: derive a test of the keystream */
}

